
function validate_add() {
	var validator = $("#form_add").validate({
		rules: {
			name: {
				required: true,
				minlength: 2
			},
			password: {
				required: true,
				minlength: 4
			}
		},
		errorPlacement: function(label, element) {
			label.insertAfter(element);
		},
		success: function(label) {
			label.html("&nbsp;").addClass("checked");
		}
	});

	return validator.form();
}

function dialog_add_(url, title, xy) {	
	$('#dialog_add').dialog('option', 'buttons', {

		"关闭": function() {
			$(this).dialog("close");
		},

		"添加": function() {
			if (!confirm("确认是否添加？")) {
				return false;
			}

			if (!validate_add()) {
				return false;
			}
			
			var form = $("#form_add")[0];

			var body = { };
			body.exten = form.exten.value;
			body.code = form.code.value;
			body.zone = form.zone.value;
			body.content = form.content.value;
			body.status = form.status.value;

			$(this).dialog("close");

			$.post('tel.php?do=Black.addPost', body, function(data) {
				$('#result').html(data);
			});
		}
	});

	dialog_add(url, title, xy);
}

function dialog_edit_(url, title, xy) {	
	$('#dialog_edit').dialog('option', 'buttons', {

		"关闭": function() {
			$(this).dialog("close");
		},

		"修改": function() {
			if (!confirm("确认是否修改？")) {
				return false;
			}
			
			var form = $("#form_edit")[0];

			var body = { };
			body.id = form.id.value;
			body.exten = form.exten.value;
			body.code = form.code.value;
			body.zone = form.zone.value;
			body.content = form.content.value;
			body.status = form.status.value;

			$(this).dialog("close");

			$.post('tel.php?do=Black.editPost', body, function(data) {
				$('#result').html(data);
			});
		}
	});

	dialog_edit(url, title, xy);
}